/**
 * @file
 * @brief Qt widget for upgrade view
 * @date 2020-10-22
 */

#pragma once

#include <QWidget>
#include "lab.h"

class State;
class QLabel;
class QSpinBox;
class QToolButton;

/**
 * @class UpgradeView
 * @brief The UpgradeView class is Qt widget for display upgrade info
 * 
 * - This widget will display next upgrade info: name, effect, price for next level
 * - Also contain QSpinBox element for control level value
 * @sa Upgrade or State
 */
class UpgradeView : public QWidget
{
    Q_OBJECT

public:
    /**
     * @brief Construct UpgradeView object
     * @param   t       upgrade type
     * @param   state   data source
     * @param   parent  Pointer to parent widget
     * @todo get default set size from state?
     */
    explicit UpgradeView( UpgradeType t, const State & state, QWidget * parent );

signals:
    /**
     * @brief Emitted on level change
     * @param   type    upgrade type
     * @param   level   new level value
     */
    void levelChanged( UpgradeType type, int level );

public slots:
    /**
     * @brief update view data
     * @param state data source
     * 
     * - Update price, level and effect fields
     * - Change background colour base on upgrade priority
     */
    void updateData(const State & state);

    /**
     * @brief buy new levels
     */
    void buyLevels();

private:
    const UpgradeType type;
    QLabel * effect;
    QLabel * price;
    QSpinBox * level;
    QToolButton * buy;
    QWidget * background;

    QColor priorityToColour(double priority);
};
